package com.bestv.search.common.service.impl;

import com.bestv.search.common.dao.SubTypeDao;
import com.bestv.search.common.dataSource.DataSourceKey;
import com.bestv.search.common.model.SubType;
import com.bestv.search.common.model.uid.UID;
import com.bestv.search.common.service.SubTypeManager;

import java.util.List;

public class SubTypeManagerImpl implements SubTypeManager {

    protected SubTypeDao subTypeDao;

    public SubTypeDao getSubTypeDao() {
        return subTypeDao;
    }

    public void setSubTypeDao(SubTypeDao subTypeDao) {
        this.subTypeDao = subTypeDao;
    }

    public SubType getSubTypeById(DataSourceKey key, Long id) {
        return subTypeDao.getSubTypeById(id);
    }

    public SubType getSubTypeByName(DataSourceKey key, String name) {
        return subTypeDao.getSubTypeByName(name);
    }

    public List<SubType> getSubTypes(DataSourceKey key) {
        return subTypeDao.getSubTypes();
    }

    public SubType saveSubType(DataSourceKey key, SubType subType) {
        if (subType.getId() == 0L) {
            subType.setId(new Long(UID.getUID(subType)));
        }
        return subTypeDao.saveOrUpdate(subType);
    }

    public void deleteSubType(DataSourceKey key, Long id) {
        subTypeDao.remove(id);
    }

    public List<SubType> getComm(DataSourceKey key) {
        return subTypeDao.getComm();
    }
}
